package cn.ranko.shiro.service;

import cn.ranko.shiro.mapper.SysPermissionMapper;
import cn.ranko.shiro.model.SysPermission;
import cn.ranko.shiro.model.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by user on 2017/9/11.
 */
@Service
public class SysPermissionService {

    @Autowired
    SysPermissionMapper sysPermissionMapper;

    public Integer insertBatch(SysRole role, String[] splits) {
        List<SysPermission> sysPermissions = new ArrayList<>();
        for(String permissionstr:splits){
            String[] split_strs = permissionstr.split("\\$");
            SysPermission permission = new SysPermission();
            permission.setRoleId(role.getRoleId());
            permission.setPermission(split_strs[0]);
            permission.setMenuId(split_strs[1]);
            sysPermissions.add(permission);
        }
        return sysPermissionMapper.insertBatch(sysPermissions);
    }

    public Integer deletePermission(Integer roleId) {
        return sysPermissionMapper.deletePermission(roleId);
    }
}
